package com.oamic.xiaomi.serverproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oamic.xiaomi.serverproject.entity.FaultReport;
import com.oamic.xiaomi.serverproject.mapper.FaultReportMapper;
import com.oamic.xiaomi.serverproject.service.FaultReportService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class FaultReportServiceImpl extends ServiceImpl<FaultReportMapper, FaultReport> implements FaultReportService {
    
    @Override
    public List<FaultReport> getAllFaultReports() {
        return list();
    }
    
    @Override
    public FaultReport getFaultReportById(Long id) {
        return getById(id);
    }
    
    @Override
    public boolean createFaultReport(FaultReport faultReport) {
        faultReport.setReportTime(LocalDateTime.now());
        faultReport.setStatus(FaultReport.FaultStatus.PENDING);
        return save(faultReport);
    }
    
    @Override
    public boolean updateFaultReport(FaultReport faultReport) {
        return updateById(faultReport);
    }
    
    @Override
    public boolean deleteFaultReport(Long id) {
        return removeById(id);
    }
    
    @Override
    public boolean updateFaultStatus(Long id, FaultReport.FaultStatus status, String resolution) {
        FaultReport faultReport = new FaultReport();
        faultReport.setId(id);
        faultReport.setStatus(status);
        faultReport.setResolution(resolution);
        return updateById(faultReport);
    }
}